package com.atguigu.hbase.demos;

import org.apache.phoenix.queryserver.client.ThinClientUtil;

import java.sql.*;

/**
 * Created by Smexy on 2022/5/17
 */
public class PhoeinxThinClientDemo {

    /*
            ①获取Connection(url,driver,username,passwd)
            ②获取PS
            ③查询，预编译sql，填充占位符
            ④执行查询，遍历结果
            ⑤关闭资源
     */
    public static void main(String[] args) throws SQLException {

        // 1. 声明url
        String url = ThinClientUtil.getConnectionUrl("hadoop103", 8765);

        // 2.获取连接
        Connection connection = DriverManager.getConnection(url);

        // 3.编译SQL语句
        PreparedStatement preparedStatement = connection.prepareStatement("select * from student");

        // 4.执行语句
        ResultSet resultSet = preparedStatement.executeQuery();

        // 5.输出结果
        while (resultSet.next()){
            System.out.println(resultSet.getString(1) + ":" + resultSet.getString(2) + ":" + resultSet.getString(3));
        }

        // 6.关闭资源
        connection.close();


    }
}
